package com.yadang.infra.controller;

import com.yadang.infra.base.ApiResult;
import com.yadang.infra.bean.Locations;
import com.yadang.infra.bean.dto.CmmDictDto;
import com.yadang.infra.service.LocationsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.lang.invoke.MethodHandles;
import java.util.List;

@Api(tags = "省市县三级菜单数据")
@RestController
@RequestMapping("/infra/location")
public class LocationsController {
    private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

    @Autowired
    private LocationsService locationsService;


    @ApiOperation("条件查询所有的字典数据")
    @PostMapping("selectLocations")
    public ApiResult<?> selectLocations(String name, String parentId, String level) {
        List<Locations> cmmDictDtoList = locationsService.selectLocations(name, parentId, level);
        return ApiResult.success(cmmDictDtoList);
    }
    @ApiOperation("查询所有的省")
    @PostMapping("selectAllProvice")
    public ApiResult<?> selectAllProvice(){
        List<String> stringList = locationsService.selectAllProvice();
        return ApiResult.success(stringList);
    }

    @ApiOperation("插入locations表")
    @PostMapping("insert")
    public ApiResult<?> insert(String provinceName, String cityName, String countyName,String level){
        String resultStr = locationsService.insert(provinceName,cityName,countyName,level);
        return ApiResult.success(resultStr);
    }

}
